map=[[1, 1, 1, 1, 0],
     [0, 0, 1, 0, 1],
     [0, 0, 0, 0, 0],
     [1, 1, 1, 0, 0],
     [0, 0, 0, 1, 1]]
hang=len(map)
lie=len(map[0])
def dfs(i,j):
    if i<0 or i>=hang or j<0 or j>=lie or map[i][j]==0:
        return
    map[i][j]=0
    dfs(i-1,j)
    dfs(i+1,j)
    dfs(i,j-1)
    dfs(i,j+1)
count=0
for i in range(hang):
    for j in range(lie):
        if map[i][j]==1:
            count+=1
            dfs(i,j)
print(count)